<style scoped>
.layout {
  border: 1px solid #d7dde4;
  background: #f5f7f9;
  position: relative;
  border-radius: 4px;
  overflow: hidden;
  height: 100%;
}
.ivu-layout-has-sider {
  height: 100%;
}
.layout-header-bar {
  background: #fff;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.1);
}
.layout-logo-left {
  width: 90%;
  height: 30px;
  background: #5b6270;
  border-radius: 3px;
  margin: 15px auto;
}
.menu-icon {
  transition: all 0.3s;
}
.rotate-icon {
  transform: rotate(-90deg);
}
.menu-item span {
  display: inline-block;
  overflow: hidden;
  width: 69px;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: bottom;
  transition: width 0.2s ease 0.2s;
}
.menu-item i {
  transform: translateX(0px);
  transition: font-size 0.2s ease, transform 0.2s ease;
  vertical-align: middle;
  font-size: 16px;
}
.collapsed-menu span {
  width: 0px;
  transition: width 0.2s ease;
}
.collapsed-menu i {
  transform: translateX(5px);
  transition: font-size 0.2s ease 0.2s, transform 0.2s ease 0.2s;
  vertical-align: middle;
  font-size: 22px;
}
.user-name {
  float: right;
  margin-right: 20px;
}
</style>
<template>
  <div class="layout">
    <Layout>
      <Sider ref="side1" hide-trigger collapsible :collapsed-width="78" v-model="isCollapsed">
        <Menu active-name="1-2" theme="dark" width="auto" :class="menuitemClasses">
          <MenuItem name="1-1">
            <Icon type="ios-navigate"></Icon>
            <span>计划排班</span>
          </MenuItem>
          <MenuItem name="1-2">
            <Icon type="ios-search"></Icon>
            <span>Option 2</span>
          </MenuItem>
          <MenuItem name="1-3">
            <Icon type="ios-settings"></Icon>
            <span>Option 3</span>
          </MenuItem>
        </Menu>
      </Sider>
      <Layout>
        <Header :style="{padding: 0}" class="layout-header-bar">
          <Icon
            @click.native="collapsedSider"
            :class="rotateIcon"
            :style="{margin: '0 20px'}"
            type="md-menu"
            size="24"
          ></Icon>
          <poptip placement="right" trigger="hover" class="user-name">
            <Avatar src="https://i.loli.net/2017/08/21/599a521472424.jpg"/>
            <div class="api" slot="content">
              <div>
                <Avatar src="https://i.loli.net/2017/08/21/599a521472424.jpg"/>
                <span>{{this.userInfo.name}}</span>
                <Button type="error" @click="loginOut">退出登录</Button>
              </div>
            </div>
          </poptip>
        </Header>
        <Content :style="height">
          <router-view/>
        </Content>
      </Layout>
    </Layout>
  </div>
</template>

<script>
import userService from "../../utils/services/userService";
import cookie from "js-cookie";
export default {
  data() {
    return {
      isCollapsed: true,
      userInfo: { name: "qian" },
      height: {
        height: "",
        background: "#fff",
        margin:"20px"
      }
    };
  },
  beforeCreate() {
    //校验用户信息
    userService.checkUserInfo(this);
  },
  created(){
    this.hh()
  },
  beforeMount() {
    cookie.get("userinfo") &&
      (this.userInfo = JSON.parse(cookie.get("userinfo")) || {});
  },
  computed: {
    rotateIcon() {
      return ["menu-icon", this.isCollapsed ? "rotate-icon" : ""];
    },
    menuitemClasses() {
      return ["menu-item", this.isCollapsed ? "collapsed-menu" : ""];
    }
  },
  methods: {
    collapsedSider() {
      this.$refs.side1.toggleCollapse();
    },
    loginOut() {
      console.log(userService);
      userService.loginOut();
    },
    hh() {
      this.height.height = window.innerHeight - 153 + "px";
    }
  }
};
</script>

